# 计算：1!+2!+3!+....+n!

# 第一种：循环一次计算每一个数的阶乘
def factorial(n):
    total = 1
    for i in range(1,n+1):
        total *= i
    return total


def f1(n):
    total = 0
    for i in range(1,n+1):
        total += factorial(i)
    return total

# 第二种：用上一步计算的结果*当前的N
def f2(n):
    total = 0
    sum_1 = 1
    for i in range(1,n+1):
        sum_1 *= i
        total += sum_1
    return total



if __name__ == '__main__':
    print(f2(4))